#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define mes(x) memset(x,0,sizeof(x))
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout)

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

template <typename T>
void write(T x){
	bool sgn = 0;
	if(x < 0) x = -x,sgn = 1;
	T stk[20],cnt = 0;
	while(x){
		stk[++cnt] = x%10;
		x/=10;
	}
	if(sgn) putchar('-');
	for(int i = cnt;i >= 1;i--) putchar(stk[i]+48);
	if(cnt == 0) putchar('0');
	putchar('\n');
}

const int MAXN = 2010;

int n,a[MAXN][MAXN],dfn[MAXN],low[MAXN],nodenum,siz,tot,stk[MAXN],top;
bool vis[MAXN];

void dfs(int x){
	dfn[x] = low[x] = ++tot;
	vis[x] = 1;stk[++top] = x;
	for(int i = 1;i <= n;i++)
		if(i != x && a[x][i]){
			if(!dfn[i]) dfs(i),low[x] = min(low[x],low[i]);
			else if(vis[i]) low[x] = min(low[x],dfn[i]);
		}
	if(low[x] == dfn[x]){
		int y;siz = 0;
		do{
			y = stk[top--];
			siz++;
		}while(x != y);
	}
}

int main (){
	n = in;
	for(int i = 1;i <= n;i++)
		for(int j = 1;j <= n;j++)
			a[i][j] = in;
	dfs(1);
	if(siz == n) puts("YES");
	else puts("NO");
	return 0;
}
